/*	This program produces Appendix Figure C.9 */

***** Set directories 
local dir_clean 	"~/Dropbox/Retirement gaming/clean"
local dir_output 	"~/Dropbox/Retirement gaming/output/dataverse"

use "`dir_clean'/mainsample_medbcw.dta", clear

local listcontrols = " i.t i.ciiu2_1stobs i.ndep_cat_1stobs i.ndep_cat " 

g indgr= 1 if ciiu1==2	// manufacturing
replace indgr = 2 if ciiu1==5 // retail
replace indgr = 3 if ciiu1==6	// transport comm
replace indgr = 4 if ciiu1==7 | ciiu1==8	// services


*** Hours per month (Figure C.9, Panel A)***
estimates clear
foreach ind in 1 2 3 4  { //    
	preserve
	keep if  empl==1 & small_1stobs==1 & indgr==`ind'
	//Normalize hours 
	sum hrsmonth if time_bcw==-1
	local meanh=r(mean)
	g Hz=hrsmonth/`meanh'		
	// Regress
	eststo out`ind': reghdfe Hz pre6 pre25 post03 post4, absorb(`listcontrols') vce(cluster i ) // semi-parametric
	restore
}
** PLOT **
label var pre25 	"2-5 Pre BCW" 
label var post03 	"0-3 Post BCW" 
label var post4 	"4+ Post BCW" 
coefplot (out1, label(Manufacturing) msymbol(O)) ///
	(out2, label(Retail/Hospitality) msymbol(T)) ///
	(out3, label(Transport/Comm) msymbol(S)) ///
	(out4, label(Services) msymbol(D)) ///
	, bylabel(Employees) ///
	||, keep(*: post03 post4) xline(0)  ///
	ciopts(recast(rcap)) levels(90 95) scheme(s2color) graphregion(color(white)) legend(cols(3)) 
graph export "`dir_output'/figureC9a.png",  replace 	
estimates clear



*** Wage per hour (Figure C.9, Panel B) ***
estimates clear
foreach ind in 1 2 3 4   { //    
	preserve
	keep if  empl==1 & indgr==`ind' & small_1stobs==1
	*Normalize wage per hour
	sum wagephr if time_bcw==-1
	local meanw=r(mean)
	g WPHz=wagephr/`meanw'
	// Regress
	eststo out`ind': reghdfe WPHz pre6 pre25 post03 post4, absorb(`listcontrols') vce(cluster i ) // semi-parametric
	restore
}
** PLOT **
label var pre25 	"2-5 Pre BCW" 
label var post03 	"0-3 Post BCW" 
label var post4 	"4+ Post BCW" 
coefplot (out1, label(Manufacturing) msymbol(O)) ///
	(out2, label(Retail/Hospitality) msymbol(T)) ///
	(out3, label(Transport/Comm) msymbol(S)) ///
	(out4, label(Services) msymbol(D)) ///
	, bylabel(Employees) ///
	||, keep(*: post03 post4) xline(0)  ///
	ciopts(recast(rcap)) levels(90 95) scheme(s2color) graphregion(color(white)) legend(cols(3))  
graph export "`dir_output'/figureC9b.png",  replace 	
estimates clear

clear all
exit
